﻿using Shop.Model.Coupon;
using Shop.Model.DB;
using Shop.RemoteModel.Coupon.Model;
using Shop.Repository.LinqHelper;
using WeDonekRpc.Client;
using WeDonekRpc.Helper.IdGenerator;
using WeDonekRpc.Model;
using WeDonekRpc.SqlSugar;

namespace Shop.Repository.lmpl
{
    internal class CouponRepository : ShopBaseRepository<DBShopCoupon, long>, ICouponRepository
    {
        public CouponRepository (ISqlClientFactory factory) : base(factory)
        {
        }

        public long Add (CouponSetArg data)
        {
            DBShopCoupon add = data.ConvertMap<CouponSetArg, DBShopCoupon>();
            add.Id = IdentityHelper.CreateId();
            add.SurplusNum = add.PutInNum;
            add.AddTime = DateTime.Now;
            add.Status = RemoteModel.CouponStatus.起草;
            base.Insert(add);
            return add.Id;
        }
        public Result[] Query<Result> (CouponQueryParam query, IBasicPage paging, out int count) where Result : class
        {
            paging.InitOrderBy("Id", true);
            return base.Query<Result>(query.ToWhere(), paging, out count);
        }
    }
}
